﻿#include "delete.h"
#include "ui_delete.h"
#include<QFile>
#include<QDebug>
#include<QtSql/QSqlDatabase>
#include<QtSql/QSqlQuery>
#include<QMessageBox>
del::del(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::del)
{
    ui->setupUi(this);
    QFile file("../del.css");
    if(file.open(QFile::ReadOnly)){
        QString str=file.readAll();
        setStyleSheet(str);
    }else{
        qDebug()<<"open del.css fail";
    }
}

del::~del()
{
delete ui;
}

void del::on_okBtn_clicked()
{
    if(!this->db.connectMysql()){
        QMessageBox::critical(this,"删","数据库连接失败,删除失败!","确定");
        return;
    }
    QSqlQuery query(QString("delete from student where id=%1").arg(this->ui->idEdit->text()));
    if(query.numRowsAffected()>0){
        QMessageBox::information(this,"删","删除成功!","确定");
    }else{
        QMessageBox::critical(this,"删","暂无此学生!","确定");
    }
}

void del::on_cancelBtn_clicked()
{
    this->close();
    this->ui->idEdit->clear();
}
